//=======================================================
// 作者：KingSley
// 描述：通过数学运算计算圆周运动路径的各点坐标保存到容器中后让物体逐坐标移动
//=======================================================
using UnityEngine;
using System.Collections;
using DG.Tweening;
using UnityEngine.UI;
using System.Collections.Generic;

namespace Babybus.Uno
{
    public class DOTweenRotation : MonoBehaviour
    {
        List<Vector3> vertices;// 用于存储圆周各点坐标
        int pointAmount;// 圆周中点的数量
        float eachAngle;
        Vector3 forward;
        int j;

        private void Start()
        {
            pointAmount = 100;// 点的数目，值越大曲线越平滑   
            eachAngle = 360f / pointAmount;
            forward = transform.forward;
            vertices = new List<Vector3>();
            j = 0;

            // 计算圆周各点坐标，并保存到容器当中
            for (int i = 0; i <= pointAmount; i++)
            {
                Vector3 pos = Quaternion.Euler(0f, eachAngle * i, 0f) * forward * 5f + transform.localPosition;
                vertices.Add(pos);
            }
        }

        private void Update()
        {
            // 移动物体位置，实现圆周运动
            j++;
            if (j <= pointAmount)
            {
                transform.DOMove(vertices[j], 0.01f);
            }
            else
                j = 0;
        }
    }
}
